package com.zjt.dao.user;

import com.zjt.entity.ClientUser;
import com.zjt.entity.Record;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: xueyanbeijing
 * Date: 12-9-7
 * Time: PM10:38
 * To change this template use File | Settings | File Templates.
 */
@Component
public class ClientUserDaoExpand implements IClientUserDaoExpand {
    private String Query_Imei = "";
    private String Count_Record_By_UserId = "select count(*) from Record u";
    private static Logger logger = LoggerFactory.getLogger(ClientUserDaoExpand.class);
    @PersistenceContext
    private EntityManager entityManager ;


    @Override
    public ClientUser getClientUserByImei(String imei) {
        Query_Imei = "select u from ClientUser u where u.imei = '"+imei+"'";
        List<ClientUser> list =  entityManager.createQuery(Query_Imei).getResultList();
        if (list!=null&&list.size()>0)
            return list.get(0);
        else
            return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public ClientUser getClientUserByEmail(String email) {
        Query_Imei = "select u from ClientUser u where u.email = '"+email+"'";
        List<ClientUser> list =  entityManager.createQuery(Query_Imei).getResultList();
        if (list!=null&&list.size()>0)
            return list.get(0);
        else
            return null;  //To change body of implemented methods use File | Settings | File Templates.
    }
}
